ActiveReports 9 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Page Report/RDL Report Walkthroughs > Export > Custom Web Exporting |
ActiveReports provides components that allow you to export your reports into several popular formats like PDF, HTML, Excel, Image, Word and XML.
The walkthrough is split up into the following activities:
Note: Although this walkthrough uses Page reports, you can also implement this using RDL reports. |
To add an ActiveReport to the Visual Studio project
GrapeCity.ActiveReports.Export.Pdf.v9
GrapeCity.ActiveReports.Export.Html.v9
GrapeCity.ActiveReports.Export.Excel.v9
GrapeCity.ActiveReports.Export.Word.v9
GrapeCity.ActiveReports.Export.Image.v9
GrapeCity.ActiveReports.Export.Xml.v9
See Adding an ActiveReport to a Project for information on adding different report layouts.
To add code to the Web Form to create the PDF Export object and export a report
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
'Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) 'Set the rendering extension and render the report. Dim pdfRenderingExtension As New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() reportDocument.Render(pdfRenderingExtension, outputProvider) Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf") Dim ms As New System.IO.MemoryStream() CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms) Response.BinaryWrite(ms.ToArray()) Response.End() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); reportDocument.Render(pdfRenderingExtension, outputProvider); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
Note: To use the one-touch printing option, add the following to the code above.
|
Warning: You need to manually license your application in order to use PDF export. |
To add code to the Web Form to create the HTML Export object and export a report
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Set the rendering extension and render the report. Dim htmlRenderingExtension As New GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() Dim setting As New GrapeCity.ActiveReports.Export.Html.Page.Settings() setting.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Galley setting.MhtOutput = True reportDocument.Render(htmlRenderingExtension, outputProvider, setting) Response.ContentType = "message/rfc822" Response.AddHeader("content-disposition", "inline;filename=MyExport.mht") Dim ms As New System.IO.MemoryStream() CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms) Response.BinaryWrite(ms.ToArray()) Response.End() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension htmlRenderingExtension = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();GrapeCity.ActiveReports.Export.Html.Page.Settings setting = new GrapeCity.ActiveReports.Export.Html.Page.Settings(); setting.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Galley; setting.MhtOutput = true; reportDocument.Render(htmlRenderingExtension, outputProvider, setting); Response.ContentType = "message/rfc822"; Response.AddHeader("content-disposition", "inline;filename=MyExport.html"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
To add code to the Web Form to create the Excel Export - Data object and export a report(RDL Reports Only)
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Set the rendering extension and render the report. Dim excelTransformationDevice As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() Dim setting As New GrapeCity.ActiveReports.Export.Excel.Page.Settings() setting.ProtectWorkbookPassword = 123 reportDocument.Render(excelTransformationDevice, outputProvider, setting) Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "inline;filename=MyExport.xls") Dim ms As New System.IO.MemoryStream() CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms) Response.BinaryWrite(ms.ToArray()) Response.End() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice excelTransformationDevice = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelTransformationDevice(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); GrapeCity.ActiveReports.Export.Excel.Page.Settings setting = new GrapeCity.ActiveReports.Export.Excel.Page.Settings(); setting.ProtectWorkbookPassword = "123"; reportDocument.Render(excelTransformationDevice, outputProvider, setting); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "inline;filename=MyExport.xls"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); |
To add code to the Web Form to create the Excel Export - Layout object and export a report
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Provide settings for your rendering output. Dim excelSetting As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings() excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = excelSetting ' Set the rendering extension and render the report. Dim excelRenderingExtension As New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings()) Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "inline;filename=MyExport.xls") Dim ms As New System.IO.MemoryStream() outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms) Response.BinaryWrite(ms.ToArray()) Response.[End]() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Provide settings for your rendering output. GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings(); excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx; GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting; // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings()); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "inline;filename=MyExport.xls"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
To add code to the Web Form to create the Word Export object and export a report
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Set the rendering extension and render the report. Dim wordRenderingExtension As New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() Dim setting As New GrapeCity.ActiveReports.Export.Word.Page.Settings() setting.UseMhtOutput = True reportDocument.Render(wordRenderingExtension, outputProvider, setting) Response.ContentType = "application/msword" Response.AddHeader("content-disposition", "inline;filename=MyExport.doc") Dim ms As New System.IO.MemoryStream() CType(outputProvider.GetPrimaryStream().OpenStream(), System.IO.MemoryStream).WriteTo(ms) Response.BinaryWrite(ms.ToArray()) Response.End() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); GrapeCity.ActiveReports.Export.Word.Page.Settings setting = new GrapeCity.ActiveReports.Export.Word.Page.Settings(); setting.UseMhtOutput = true; reportDocument.Render(wordRenderingExtension, outputProvider, setting); Response.ContentType = "application/msword"; Response.AddHeader("content-disposition", "inline;filename=MyExport.doc"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
To add code to the Web Form to create the Image Export object and export a report
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Set the rendering extension and render the report. Dim imageRenderingExtension As New GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() Dim setting As New GrapeCity.ActiveReports.Export.Image.Page.Settings() setting.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG reportDocument.Render(imageRenderingExtension, outputProvider, setting) Response.ContentType = "image/jpeg" Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg") Dim ms As New System.IO.MemoryStream() ' Get the first page of the report CType(outputProvider.GetSecondaryStreams()(0).OpenStream(), System.IO.MemoryStream).WriteTo(ms) Response.BinaryWrite(ms.ToArray()) Response.End() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension imageRenderingExtension = new GrapeCity.ActiveReports.Export.Image.Page.ImageRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); GrapeCity.ActiveReports.Export.Image.Page.Settings setting = new GrapeCity.ActiveReports.Export.Image.Page.Settings(); setting.ImageType = GrapeCity.ActiveReports.Export.Image.Page.Renderers.ImageType.JPEG; reportDocument.Render(imageRenderingExtension, outputProvider, setting); Response.ContentType = "image/jpeg"; Response.AddHeader("content-disposition", "inline;filename=MyExport.jpg"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); // Get the first page of the report outputProvider.GetSecondaryStreams()[0].OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
To add code to the Web Form to create the XML Export object and export a report.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
' Provide the page report you want to render. Dim report As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("") + "\CustomWebExporting.rdlx")) Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(report) ' Set the rendering extension and render the report. Dim xmlRenderingExtension As New GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension() Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider() reportDocument.Render(xmlRenderingExtension, outputProvider) Response.ContentType = "application/xml" Response.AddHeader("content-disposition", "inline;filename=MyExport.xml") Dim ms As New System.IO.MemoryStream() outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms) Response.BinaryWrite(ms.ToArray()) Response.[End]() |
To write the code in C#
C# code. Paste INSIDE the Page Load event. |
Copy Code
|
---|---|
// Provide the page report you want to render. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("") + "\\CustomWebExporting.rdlx")); GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report); // Set the rendering extension and render the report. GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension xmlRenderingExtension = new GrapeCity.ActiveReports.Export.Xml.Page.XmlRenderingExtension(); GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider(); reportDocument.Render(xmlRenderingExtension, outputProvider); Response.ContentType = "application/xml"; Response.AddHeader("content-disposition", "inline;filename=MyExport.xml"); System.IO.MemoryStream ms = new System.IO.MemoryStream(); outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms); Response.BinaryWrite(ms.ToArray()); Response.End(); |
To run the project
Press F5 to run the project.